package 集合.LIST;

import java.util.ArrayList;

public class ArrayListDemo7 {
    public static void main(String[] args) {
        ArrayList<ArrayListDemo7Phone>list=new ArrayList<>();
        ArrayListDemo7Phone p1=new ArrayListDemo7Phone("小米",1999);
        ArrayListDemo7Phone p2=new ArrayListDemo7Phone("苹果",8000);
        ArrayListDemo7Phone p3=new ArrayListDemo7Phone("锤子",2999);
        list.add(p1);
        list.add(p2);
        list.add(p3);
        ArrayList<ArrayListDemo7Phone>list1=GetPrice(list);//调用方法；
        //遍历获得数据
        for (int i = 0; i < list1.size(); i++) {
            ArrayListDemo7Phone phone = list1.get(i);
            System.out.println(phone.getBrand()+","+phone.getPrice());
        }

    }
    public static ArrayList<ArrayListDemo7Phone> GetPrice(ArrayList<ArrayListDemo7Phone>list){
        ArrayList<ArrayListDemo7Phone> resultlist=new ArrayList();//以数组的形式，当有多个对象时，通过返回数组，获得返回值。
        for (int i = 0; i < list.size(); i++) {
            ArrayListDemo7Phone p=list.get(i);
            int price = p.getPrice();
            if (price<3000){
                resultlist.add(p);
            }
        }
        return resultlist;
    }
}

